package cn.wolfcode.wolf2w.job;

import cn.wolfcode.wolf2w.redis.IStrategyStatisVORedisService;
import cn.wolfcode.wolf2w.redis.IStrategyStatisVORedisService;
import cn.wolfcode.wolf2w.redis.util.RedisKeys;
import cn.wolfcode.wolf2w.redis.vo.StrategyStatisVO;
import cn.wolfcode.wolf2w.service.IStrategyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 将redis中数据进行持久化
 */
@Component
public class RedisDataPersistenceJob {

    @Autowired
    private IStrategyStatisVORedisService strategyStatisVORedisService;

    @Autowired
    private IStrategyService strategyService;



    //定时任务标签
    @Scheduled(cron = "0/20 * * * * ? ")
    public void doWork(){
        //strategy_statis_vo:*
        String pattern = RedisKeys.STRATEGY_STATIS_VO.join("*");
        List<StrategyStatisVO> vos =  strategyStatisVORedisService
                .listStrategyVoByPattern(pattern);

        for (StrategyStatisVO vo : vos) {
            strategyService.updateStatisVo(vo);
        }
    }
}
